<template>
	<view class="current-cycle">
		<!-- 历史周期详情 -->
		<view class="top-flex">
			<view class="left">
				<view class="label">我的安全积分</view>
				<view class="item-flex">
					<view class="num">{{info.grade}}</view>
					<view class="text">上限100</view>
				</view>
				<view class="item-flex">
					<view class="title">统计日期：</view>
					<view class="text">{{info.evalSection}}</view>
				</view>
				<view class="item-flex">
					<view class="title">评估期：</view>
					<view class="text">{{info.evalSectionStage}}</view>
				</view>
				<!-- <view class="btn" @click="$goBack('appeal-history')">申诉历史</view> -->
			</view>
			<view class="right">
				<view class="uqrcode">
					<view class="uqrcode-border">
						<canvas canvas-id="uqrcode"></canvas>
					</view>
				</view>
				<view class="uqrcode-text">失效</view>
			</view>
		</view>
		<view class="apply-list">
			<table-list :columns="columns" :list="assArchiveDetailList" :childrenColumns="childrenColumns"></table-list>
		</view>
	</view>
</template>

<script>
	import uQRCode from '@/common/uqrcode.js' //引入uqrcode.js
	import tableList from "@/components/tool-card/table-list";
	import {
		dateFormat
	} from "@/common/util.js"
	export default {
		components: {
			tableList
		},
		data() {
			return {
				// 安全码信息
				uqrCodeList: {
					A: {
						color: '#409EFF',
						text: '蓝码'
					},
					B: {
						color: '#FFD04D',
						text: '黄码'
					},
					C: {
						color: '#F56C6C',
						text: '红码'
					}
				},
				uqrCodeType: 'A',
				info: {
					evalSection: '',
					score: '',
					evalTime: ""
				},
				// 当前周期积分详情
				assArchiveDetailList: [],
				childrenColumns: {
					show: true,
					key: 'archiveDetailVOList',
					columns: [{
							title: "#",
							type: 'index',
							$width: '2em',
						},
						{
							title: '发生日期',
							$width: '120rpx',
							format: ({
								item
							}) => {
								return item.evalSection.replace(/年|月|日/g, (k) => k == '日' ? '' : '-')
							}
						},
						{
							title: '描述',
							key: 'itemStatement',
						},
						{
							title: '扣分',
							key: 'itemScore',
							$width: '35px',
						},
					]
				},
				columns: [{
						title: "序号",
						type: 'index',
						$width: '2em',

					},
					{
						title: '指标项',
						key: 'indicatorItem',
					},
					{
						title: '分值',
						key: 'itemScore',
						$width: '70px',
					}
				],

			}
		},
		computed: {
			userInfo() {
				return this.$store.getters.getUserInfo;
			}
		},
		methods: {
			//二维码生成
			qrFun(text) {
				uQRCode.make({
					canvasId: 'uqrcode',
					componentInstance: this,
					text: text,
					size: 60,
					margin: 0,
					backgroundColor: '#ffffff',
					foregroundColor: '#999',
					fileType: 'jpg',
					errorCorrectLevel: uQRCode.errorCorrectLevel.H,
					success: res => {
						// console.log(res);
					},
				})
			}
		},
		onLoad(e) {
			const resData = [JSON.parse(e.param)];
			Object.assign(this.info, resData[0])
			const qrData = {
				uid: this.userInfo.empIdCard,
				id: resData[0].id,
				// archiveCode: resData[0].archiveCode,
				// archiveName: resData[0].archiveName,
				// evalSection: resData[0].evalSection,
				levels: resData[0].levels,
				score: resData[0].score,
				datetime: dateFormat(),
			}
			this.uqrCodeType = qrData.levels
			this.qrFun(JSON.stringify(qrData)); //调用生成二维码方法

			this.$api.staffScoreDetail({
				archiveId: resData[0].archiveId,
				period: resData[0].period,
				evalSection: resData[0].evalSection,
			}).then(res => {
				this.assArchiveDetailList = res.data.data.assArchiveDetailSumList;
			})
		}
	}
</script>

<style lang="scss">
	.current-cycle {
		padding: 20rpx 30rpx;

		.top-flex {
			display: flex;
			align-items: center;
			background: #FFFFFF;
			box-shadow: 0px 4rpx 6rpx 1px rgba(84, 83, 83, 0.16);
			border-radius: 16rpx;
			padding: 24rpx 30rpx;
			margin-bottom: 30rpx;

			.left {
				flex: 1;

				.label {
					font-size: 24rpx;
					color: #999;
					margin-bottom: 30rpx;
				}

				.item-flex {
					display: flex;
					font-size: 24rpx;
					color: #999;
					line-height: 32rpx;
					margin-bottom: 16rpx;

					.title {
						color: #999;
					}

					.num {
						font-size: 36rpx;
						padding-right: 30rpx;
					}
				}

				.btn {
					line-height: 42rpx;
					background: #F2BA38;
					border-radius: 22rpx;
					font-size: 24rpx;
					color: #fff;
					display: inline-block;
					padding: 0 20rpx;
				}
			}

			.right {
				// 此处部分用px单位，因为二维码生成的大小单位是px
				width: 72px;
				border-left: 1px solid #eee;
				padding: 10px 0 10px 20px;

				.uqrcode-border {
					margin: 0 auto;
					width: 60px;
					height: 60px;
					border: 6rpx solid #999;
					padding: 6rpx;
					margin-bottom: 12rpx;
				}

				.uqrcode-text {
					text-align: center;
					font-size: 28rpx;
					color: #999;
				}
			}
		}
	}

	.apply-list {
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx 1px rgba(84, 83, 83, 0.16);
		border-radius: 16rpx;
		padding: 24rpx 10rpx;
	}
</style>
